package com.homeWork03;

public class SellTicket implements Runnable {

    public int ticket=100;
   public Object  obj = new Object();

    @Override
    public void run() {
        while (true) {
            synchronized (SellTicket.class) {
                if (ticket == 0) {
                    break;
                }
                ticket--;
                System.out.println(Thread.currentThread().getName()+"卖了一张票，还剩"+ticket+"张票");
                try {
                    Thread.sleep(10);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}
